#include <iostream>
#include <stack>
#include <string>
using namespace std;

/**
  * @方法: 模拟
  * @时间复杂度: o()
  * @空间复杂度: o()
  * @评价:
*/
string decodeString1(string s) {
    if (s.find('[') == string::npos) return s;
    if (isdigit(s[0]) && s.find(']') == s.length() - 1) {
        int left = s.find('[');
        int cnt = stoi(s.substr(0, left));
        string ans = "";
        for (int i = 0; i < cnt; i++)
            ans += s.substr(left + 1, s.length() - 2 - (left + 1) + 1);
        return ans;
    }
    string ans = "";
    int left = s.find('[');
    int right = -1;
    int nl;
    while(left != string::npos){
        nl = left - 1;
        while( nl >= 0 && isdigit(s[nl])) nl--;
        ans += s.substr(right+1, nl - (right+1) + 1);
        int cnt=0;
        for(int i=left+1;i<s.length();i++){
            if(s[i] == '[') cnt++;
            else if(s[i] == ']' && cnt == 0) {
                right = i;
                break;
            }else if(s[i] == ']') cnt--;
        }
        string tmp = decodeString(s.substr(left+1, right-left-1) );
        int num = stoi(s.substr(nl+1,left-(nl+1)));
        for(int i=0;i<num;i++) ans += tmp;
        left = s.find('[', right+1);
    }
    if(right == s.length()-1) return ans;
    ans += s.substr(right+1,s.length()-(right+1));
    return ans;
}

string strs[100];
int nums[100];
int tn;
int ts;
string decodeString(string s) {
    if(s.find('[') == string::npos) return s;
    if (isdigit(s[0]) && s.find(']') == s.length() - 1) {
        int left = s.find('[');
        int cnt = stoi(s.substr(0, left));
        string ans = "";
        for (int i = 0; i < cnt; i++)
            ans += s.substr(left + 1, s.length() - 2 - (left + 1) + 1);
        return ans;
    }
    int cnt = 0;
    
    for(i=0;i<s.length();i++){
        
    }
}


int main() {
    string s = "3[a]2[bc]";
    string ans = decodeString(s);
    cout << ans << endl;
    return 0;
}